import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        boolean flg = false;//代表不是负数
        String table = "0123456789ABCDEF";
        StringBuilder sb = new StringBuilder();
        if(m ==0){
            System.out.print(0);
            return;
        } 
        if(m < 0){
            flg = true;
            m = -m;
        }
        while(m != 0){
            sb.append(table.charAt(m % n));
            m = m/n;
        }
        if(flg){
            //表示是负数的时候
            sb.append("-");
        }
        System.out.print(sb.reverse());
            
    }
}